import 'dart:convert';

import 'express.dart';

class SaveResult{

  List<dynamic> rowNo=[];
  int costTime=0;
  List<GameExpress> winSteps=[];

  SaveResult.create(this.rowNo, this.costTime, this.winSteps);

  SaveResult.from(Map<String,dynamic> maps){

    var steps=maps['winSteps'];
    List<GameExpress> rsteps=[];
    for(var contetmap in steps){
      rsteps.add(GameExpress(contetmap['n1'],contetmap['n2'], contetmap['execute'],contetmap['result']));
    }
    SaveResult.create(this.rowNo=maps['rowNo'],this.costTime=maps['costTime'],this.winSteps=rsteps);
  }

  bool isSuccess(){

    return winSteps.length!=0;
  }

  @override
  String toString() {

    List<Map<String,dynamic>> steps=[];
    for (var element in winSteps) {
      steps.add(element.toMap());
    }

    return json.encode({
      "rowNo":rowNo,
      "costTime":costTime,
      "winSteps":steps
    });
    return 'SaveResult{rowNo: $rowNo, costTime: $costTime, winSteps: $winSteps}';
  }


}